package metrictree.test;

import metrictree.functors.BinaryFunctor;
import metrictree.functors.impls.EuclideanDistanceFunctor;
import metrictree.trees.Pair;
import metrictree.utils.GenerateData;
import metrictree.utils.TopNHeap;

public class SequenceSearch {
	 static float[][]dict ;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int persize=40;
		dict=GenerateData.generate(100000, persize);
		
		float threshold=18f;
		long time=System.nanoTime();
		TopNHeap<Pair<Float, float[]>> topNHeap=find(GenerateData.generate(persize), threshold,1000);
		System.err.println("search time:"+(System.nanoTime()-time)/1000000);
		System.err.println(topNHeap);
		
	}

	private static TopNHeap<Pair<Float, float[]>> find(float[] generate, float threshold, int topk) {
		TopNHeap<Pair<Float, float[]>> topNHeap=new TopNHeap<Pair<Float,float[]>>(topk);
		//BinaryFunctor<float[], float[], Float> metric=new EuclideanDistanceFunctor();
		System.out.println(dict.length);
		for(int i=0;i<dict.length;i++){
			BinaryFunctor<float[], float[], Float> metric=new EuclideanDistanceFunctor();
			Float distance=metric.fn(generate, dict[i]);
			if(distance<=threshold){
				topNHeap.addToHeap(new Pair<Float, float[]>(distance, dict[i]));
			}
		}
		return topNHeap;
	}

}
